const vmShare = weex.requireModule('vmShare')
const bUrl = weex.config.env.request

vmShare.initShare({
  umeng: '5cc3c1190cafb2ca8c000cd5',
  wx: 'wxcb1dbf63e1309ab3',
  wxSecret: '7c23fcc15edecdcb7b230817a6804c00',
  qq: '1108908803',
  qqSecret: 'uxgsVoWLSjxl81gA',
  weibo: '3921700954',
  weiboSecret: '04b48b094faeb16683c32669824ebdad',
  weiboCallback: 'http://sns.whalecloud.com'
})

const Share = Object.create(null)
Share.install = Vue => {
  Vue.prototype.$share = {
    text({ title = '', image = '' }) {
      return new Promise((resolve, reject) => {
        vmShare.shareText({ title, image }, ({ status, errorMsg, data }) => {
          status === 0 ? resolve(data) : reject({ status, errorMsg, data })
        })
      })
    },
    url({ title = '', url = '', image = '', description = '', baseUrl = bUrl }) {
      return new Promise((resolve, reject) => {
        vmShare.shareUrl({ title, url: `${baseUrl}${url}`, image, description }, ({ status, errorMsg, data }) => {
          status === 0 ? resolve(data) : reject({ status, errorMsg, data })
        })
      })
    }
  }
}

Vue.use(Share)
